﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TournamentDatabase.Controls
{
	/// <summary>
	/// Interaction logic for SearchField.xaml
	/// </summary>
	public partial class SearchField : UserControl
	{
		public delegate void SearchHandler(string searchText);

		public event SearchHandler Search;

		string m_searchText;

		public string SearchText
		{
			get { return m_searchText; }
			set { m_searchText = value; }
		}

		public string BackgroundSearchText
		{
			get { return searchTextBox.BackgroundText; }
			set { searchTextBox.BackgroundText = value; }
		}

		public SearchField()
		{
			InitializeComponent();
		}

		private void searchButton_Click(object sender, RoutedEventArgs e)
		{
			OnSearch(m_searchText);
		}

		private void BackgroundTextBox_KeyDown(object sender, KeyEventArgs e)
		{
			if (e.Key == Key.Enter)
			{
				OnSearch(m_searchText);
				e.Handled = true;
			}
		}

		protected void OnSearch(string searchText)
		{
			if (Search != null)
			{
				Search(searchText);
			}
		}
	}
}
